{% extends 'blog_base.html' %}
{% block title %}我的主页{% endblock %}

{% block main %}
    <div class="container-fluid">
        <div class="row g-4">
            <!-- 左侧消息列表 -->
            <div class="col-lg-4">
                <div class="card shadow-sm h-100">
                    <div class="card-header bg-primary text-white position-sticky top-0 z-index-1">
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <h5 class="mb-0">消息中心</h5>
                                <small>右键可删除信息</small>
                            </div>
                            <!-- 新增全局展开/折叠按钮 -->
                            <button id="toggleAll" class="btn btn-light btn-sm">
                                <i class="bi bi-chevron-double-down"></i>
                                <span>展开全部</span>
                            </button>
                        </div>
                    </div>

                    <!-- 可滚动区域 -->
                    <div class="scrollable-container">
                        {% for blog in blogs %}
                            <div class="card border-0 mb-3 hover-lift">
                                <!-- 标题区域 -->
                                <div class="card-header bg-light cursor-pointer"
                                     data-bs-toggle="collapse"
                                     data-bs-target="#comments-{{ blog.id }}">
                                    <div class="d-flex justify-content-between align-items-center">
                                        <div>
                                            <h6 class="mb-0 text-primary">
                                                <i class="bi bi-chevron-down toggle-icon me-2"></i>
                                                {{ blog.title }}
                                            </h6>
                                            <small class="text-muted">
                                                <i class="bi bi-clock-history me-1"></i>
                                                {{ blog.pub_time|date:"Y/m/d H:i" }}
                                            </small>
                                        </div>
                                        {% if blog.comments.count > 0 %}
                                            <span class="badge bg-info">
                                    {{ blog.comments.count }} 条评论
                                </span>
                                        {% endif %}
                                    </div>
                                </div>

                                <!-- 评论区域 -->
                                <div id="comments-{{ blog.id }}" class="comment-collapse">
                                    <div class="card-body pt-0">
                                        {% for comment in blog.comments.all %}
                                            <div class="comment-item p-3 mb-3 rounded bg-light">
                                                <div class="d-flex align-items-center mb-2">
                                                    <img src="{% static 'image/cat.png' %}"
                                                         class="rounded-circle me-2"
                                                         width="32"
                                                         height="32"
                                                         alt="用户头像">
                                                    <div class="flex-grow-1">
                                                        <div class="d-flex justify-content-between align-items-center">
                                                            <h6 class="mb-0 text-success">
                                                                {{ comment.author.name }}
                                                                <small class="text-muted ms-2">
                                                                    {{ comment.created_at|timesince }}前
                                                                </small>
                                                            </h6>
                                                            <!-- 回复按钮 -->
                                                            <a href="{% url 'bootstrapApp:blog_detail' blog_id=blog.id %}#comment-{{ comment.id }}"
                                                               class="btn btn-link btn-sm text-decoration-none"
                                                               title="回复评论">
                                                                <i class="bi bi-reply"></i>
                                                                回复
                                                            </a>
                                                        </div>
                                                        <p class="mb-0 text-dark lh-sm mt-2">
                                                            {{ comment.content|truncatechars:120 }}
                                                        </p>
                                                    </div>
                                                </div>
                                            </div>
                                        {% endfor %}
                                    </div>
                                </div>
                            </div>
                        {% endfor %}
                    </div>
                </div>
            </div>

            <!-- 右侧内容区 -->
            <div class="col-lg-8">
                <!-- 用户信息卡片 -->
                <div class="card mb-4 shadow-sm">
                    <div class="card-body">
                        <div class="d-flex align-items-center">
                            <img src="{% static 'image/cat.png' %}"
                                 class="rounded-circle me-3"
                                 width="80"
                                 height="80"
                                 alt="用户头像">
                            <div class="flex-grow-1">
                                <h3 class="mb-1">{{ user_myself.username }}</h3>
                                <div class="d-flex text-muted">
                                    <small class="me-3">
                                        <i class="bi bi-calendar me-1"></i>
                                        注册于 {{ user_myself.date_joined|date:"Y-m-d" }}
                                    </small>
                                    <small>
                                        <i class="bi bi-clock-history me-1"></i>
                                        最后登录 {{ user_myself.last_login|timesince }}前
                                    </small>
                                </div>

                                <!-- 个人简介 -->
                                <div class="mt-3">
                                    <p class="mb-0 text-break" style="color: #6c757d; font-size: 0.95rem;">
                                        <i class="bi bi-person-lines-fill me-2"></i>
                                        {{ user_myself.profile.bio|default:"这个人很懒什么都没写，但ta的存在本身就是一道光，床前明月光，疑是地上霜，举头望明月，低头思故乡" }}
                                    </p>
                                </div>

                                <!-- 新增社交信息 -->
                                <div class="d-flex align-items-center mt-3">
                                    {% if user_myself.profile.website %}
                                        <a href="{{ user_myself.profile.website }}" class="text-decoration-none me-3"
                                           target="_blank">
                                            <i class="bi bi-globe" style="color: #6c757d;"></i>
                                        </a>
                                    {% endif %}

                                    {% if user_myself.profile.github %}
                                        <a href="{{ user_myself.profile.github }}" class="text-decoration-none me-3"
                                           target="_blank">
                                            <i class="bi bi-github" style="color: #6c757d;"></i>
                                        </a>
                                    {% endif %}

                                    {% if user_myself.profile.weibo %}
                                        <a href="{{ user_myself.profile.weibo }}" class="text-decoration-none me-3"
                                           target="_blank">
                                            <i class="bi bi-wechat" style="color: #6c757d;"></i>
                                        </a>
                                    {% endif %}

                                    <!-- 示例展示（实际应替换为动态数据） -->
                                    <span class="badge bg-secondary me-2">
                                        <i class="bi bi-geo-alt"></i> 北京
                                    </span>
                                    <span class="badge bg-info me-2">
                                        <i class="bi bi-balloon"></i> 天秤座
                                    </span>
                                    <span class="badge bg-info me-2">
                                        <i class="bi bi-balloon"></i> 联系方式:123456
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 数据统计卡片 -->
                <div class="row g-4 mb-4">
                    <!-- 博客数量卡片 -->
                    <div class="col-md-6 col-xl-3">
                        <a href="{% url 'bootstrapApp:blog_myself_to_myBlogs' user_id=user_myself.id %}"
                           class="text-decoration-none d-block h-100">
                            <div class="card bg-primary text-white shadow-sm hover-transform">
                                <div class="card-body">
                                    <div class="d-flex justify-content-between align-items-center">
                                        <div>
                                            <h5 class="card-title mb-1">我的博客</h5>
                                            <h2 class="mb-0">{{ blogs.all|length }}</h2>
                                        </div>
                                        <i class="bi bi-file-text display-6 opacity-25"></i>
                                    </div>
                                </div>
                            </div>
                        </a>
                    </div>

                    <!-- 评论数卡片 -->
                    <div class="col-md-6 col-xl-3">
                        <a href="#" class="text-decoration-none d-block h-100">
                            <div class="card bg-success text-white shadow-sm hover-transform">
                                <div class="card-body">
                                    <div class="d-flex justify-content-between align-items-center">
                                        <div>
                                            <h5 class="card-title mb-1">评论数</h5>
                                            <h2 class="mb-0">{{ stats.comment_count }}</h2>
                                        </div>
                                        <i class="bi bi-chat-dots display-6 opacity-25"></i>
                                    </div>
                                </div>
                            </div>
                        </a>
                    </div>

                    <!-- 粉丝数卡片 -->
                    <div class="col-md-6 col-xl-3">
                        <a href="#" class="text-decoration-none d-block h-100">
                            <div class="card bg-info text-white shadow-sm hover-transform">
                                <div class="card-body">
                                    <div class="d-flex justify-content-between align-items-center">
                                        <div>
                                            <h5 class="card-title mb-1">粉丝数</h5>
                                            <h2 class="mb-0">{{ stats.follower_count }}</h2>
                                        </div>
                                        <i class="bi bi-people display-6 opacity-25"></i>
                                    </div>
                                </div>
                            </div>
                        </a>
                    </div>

                    <!-- 收藏数卡片 -->
                    <div class="col-md-6 col-xl-3">
                        <a href="#" class="text-decoration-none d-block h-100">
                            <div class="card bg-warning text-dark shadow-sm hover-transform">
                                <div class="card-body">
                                    <div class="d-flex justify-content-between align-items-center">
                                        <div>
                                            <h5 class="card-title mb-1">收藏数</h5>
                                            <h2 class="mb-0">89</h2>
                                        </div>
                                        <i class="bi bi-star display-6 opacity-25"></i>
                                    </div>
                                </div>
                            </div>
                        </a>
                    </div>
                </div>


                <!-- 快速操作区 -->
                <div class="card shadow-sm mb-4">
                    <div class="card-body">
                        <h5 class="card-title mb-4">快速操作</h5>
                        <div class="row g-3">
                            <div class="col-6 col-md-3">
                                <a href="{% url 'bootstrapApp:blog_pub' %}"
                                   class="btn btn-outline-primary w-100 py-3">
                                    <i class="bi bi-pencil-square me-2"></i>
                                    写博客
                                </a>
                            </div>
                            <div class="col-6 col-md-3">
                                <button class="btn btn-outline-success w-100 py-3">
                                    <i class="bi bi-file-earmark me-2"></i>
                                    草稿箱(3)
                                </button>
                            </div>
                            <div class="col-6 col-md-3">
                                <a href="{% url 'bootstrapApp:blog_informationChange' user_id=user_myself.id %}">
                                    <button class="btn btn-outline-info w-100 py-3">
                                        <i class="bi bi-gear me-2"></i>
                                        设置信息
                                    </button>
                                </a>
                            </div>
                            <div class="col-6 col-md-3">
                                <button class="btn btn-outline-danger w-100 py-3">
                                    <i class="bi bi-box-arrow-right me-2"></i>
                                    退出
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 最近活动时间线 -->
                <!-- 修改位置：最近活动时间线卡片 -->
                <div class="card shadow-sm">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center mb-4">
                            <h5 class="card-title mb-0">最近活动</h5>
                            <button class="btn btn-sm btn-outline-secondary"
                                    data-bs-toggle="collapse"
                                    data-bs-target="#timelineCollapse">
                                <i class="bi bi-chevron-down toggle-icon"></i>
                                <span>折叠</span>
                            </button>
                        </div>
                    点击折叠打开活动内容
                        <!-- 添加可折叠容器 -->
                        <div id="timelineCollapse" class="collapse show">
                            <div class="timeline">
                                {% for activity in recent_activities %}
                                    <div class="timeline-item">
                                        <a href="{% url 'bootstrapApp:blog_detail' blog_id=activity.object_id %}"
                                           class="text-decoration-none text-dark card-hover">
                                            <div class="timeline-icon bg-{{ activity.get_icon_color }}">
                                                <i class="bi bi-{{ activity.get_icon_name }}"></i>
                                            </div>
                                            <div class="timeline-content">
                                                <small class="text-muted">{{ activity.created_at|timesince }}前</small>
                                                <p class="mb-0">{{ activity.content }}</p>
                                            </div>
                                        </a>
                                    </div>
                                {% endfor %}

                                <!-- 其他时间线项保持原有结构，包裹在timeline容器内 -->
                                {% for comment in user_myself.comments.all %}
                                    <div class="timeline-item">
                                        <a href="{% url 'bootstrapApp:blog_detail' blog_id=comment.blog.id %}"
                                           class="text-decoration-none text-dark card-hover">
                                            <div class="timeline-icon bg-{{ activity.get_icon_color }}">
                                                <i class="bi bi-{{ activity.get_icon_name }}"></i>
                                            </div>
                                            <div class="timeline-content">
                                                <small class="text-muted">59分钟前</small>
                                                <p class="mb-0">评论内容：{{ comment.content }}</p>
                                            </div>
                                        </a>
                                    </div>
                                {% endfor %}

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 右键菜单 -->
    <div class="dropdown-menu shadow" id="messageContextMenu">
        <a class="dropdown-item" href="#"><i class="bi bi-check2 me-2"></i>标记已读</a>
        <a class="dropdown-item text-danger" href="#"><i class="bi bi-trash me-2"></i>删除消息</a>
        <div class="dropdown-divider"></div>
        <a class="dropdown-item" href="#"><i class="bi bi-archive me-2"></i>归档消息</a>
    </div>
{% endblock %}

{% block head %}
    {#<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">#}
    <style>
        /* 时间线折叠按钮样式 */
        [data-bs-target="#timelineCollapse"] {
            transition: all 0.3s ease;
            padding: 0.25rem 0.75rem;
            border-radius: 20px;
        }

        [data-bs-target="#timelineCollapse"]:hover {
            background-color: rgba(0, 0, 0, 0.05);
        }

        /* 时间线容器过渡动画 */
        #timelineCollapse {
            transition: opacity 0.3s ease, height 0.3s ease;
        }

        /* 调整时间线项间距 */
        .timeline-item {
            margin-bottom: 1.5rem;
            transition: transform 0.3s ease;
        }

        .timeline-item:hover {
            transform: translateX(5px);
        }

        /* 自定义样式 */
        .hover-effect:hover {
            background-color: #f8f9fa;
            transform: translateX(5px);
            transition: all 0.2s;
        }

        .avatar-placeholder {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .timeline {
            position: relative;
            padding-left: 40px;
        }

        .timeline-item {
            position: relative;
            margin-bottom: 2rem;
        }

        .timeline-icon {
            position: absolute;
            left: -40px;
            top: 0;
            width: 32px;
            height: 32px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
        }

        .timeline-content {
            border-left: 2px solid #dee2e6;
            padding-left: 1.5rem;
            padding-bottom: 1rem;
        }

        .card-title {
            font-weight: 600;
            color: #2c3e50;
        }

        .dropdown-menu {
            min-width: 200px;
            border: 1px solid rgba(0, 0, 0, .1);
        }


        /* 修复卡片布局的必备样式 */
        .hover-transform {
            transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
            border: 1px solid transparent;
        }

        .hover-transform:hover {
            transform: translateY(-3px);
            box-shadow: 0 4px 18px rgba(0, 0, 0, 0.1);
            border-color: rgba(0, 0, 0, 0.1);
        }

        /* 确保链接卡片高度统一 */
        a.d-block.h-100 {
            height: 100%;
        }

        /* 移除标题默认链接样式 */
        .card-title {
            text-decoration: none !important;
        }

        /* 悬停提升效果 */
        .hover-lift {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        .hover-lift:hover {
            transform: translateY(-3px);
            box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.1);
        }

        /* 渐变背景 */
        .bg-gradient-light {
            background: linear-gradient(90deg, rgba(248, 249, 250, 1) 0%, rgba(255, 255, 255, 1) 100%);
        }

        /* 评论项间隔线 */
        .comment-item:not(:last-child) {
            border-bottom: 1px solid #dee2e6;
            padding-bottom: 1.25rem;
        }

        /* 新增自定义样式 */
        .scrollable-container {
            height: calc(100vh - 200px);
            overflow-y: auto;
            scrollbar-width: thin;
            scrollbar-color: #dee2e6 transparent;
        }

        .comment-collapse {
            transition: all 0.3s ease;
            max-height: 0;
            overflow: hidden;
        }

        .comment-collapse.show {
            max-height: 1000px;
        }

        .toggle-icon {
            transition: transform 0.3s ease;
        }

        .toggle-icon.rotated {
            transform: rotate(180deg);
        }

        /* 回复按钮悬停效果 */
        .btn-link:hover {
            color: var(--bs-primary) !important;
            transform: translateX(3px);
            transition: all 0.2s ease;
        }

        /* 全局按钮样式 */
        #toggleAll {
            transition: all 0.3s ease;
            border-radius: 20px;
            padding: 0.25rem 1rem;
        }

        #toggleAll:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }


    </style>
    <script>
        // 时间线折叠按钮交互
        document.querySelector('#timelineCollapse').addEventListener('show.bs.collapse', function () {
            document.querySelector('[data-bs-target="#timelineCollapse"] span').textContent = '折叠';
            document.querySelector('[data-bs-target="#timelineCollapse"] .toggle-icon').classList.add('rotated');
        });

        document.querySelector('#timelineCollapse').addEventListener('hide.bs.collapse', function () {
            document.querySelector('[data-bs-target="#timelineCollapse"] span').textContent = '展开';
            document.querySelector('[data-bs-target="#timelineCollapse"] .toggle-icon').classList.remove('rotated');
        });

        // 全局展开/折叠功能
        const toggleAllButton = document.getElementById('toggleAll');
        let isAllExpanded = false;

        toggleAllButton.addEventListener('click', function () {
            const collapses = document.querySelectorAll('.comment-collapse');
            const icons = document.querySelectorAll('.toggle-icon');

            if (isAllExpanded) {
                // 折叠全部
                collapses.forEach(collapse => {
                    new bootstrap.Collapse(collapse, {toggle: false}).hide();
                });
                icons.forEach(icon => {
                    icon.classList.remove('rotated');
                });
                this.innerHTML = `<i class="bi bi-chevron-double-down"></i><span>展开全部</span>`;
            } else {
                // 展开全部
                collapses.forEach(collapse => {
                    new bootstrap.Collapse(collapse, {toggle: false}).show();
                });
                icons.forEach(icon => {
                    icon.classList.add('rotated');
                });
                this.innerHTML = `<i class="bi bi-chevron-double-up"></i><span>折叠全部</span>`;
            }
            isAllExpanded = !isAllExpanded;
        });

        // 单个折叠面板交互
        document.querySelectorAll('[data-bs-toggle="collapse"]').forEach(button => {
            button.addEventListener('click', function () {
                const target = document.querySelector(this.dataset.bsTarget);
                const icon = this.querySelector('.toggle-icon');
                icon.classList.toggle('rotated', target.classList.contains('show'));
            });
        });
    </script>
{% endblock %}